/**
 * \file dmxcon/drivers/nulldev.c
 * \author Christian Spoo
 * \date 07.08.2010
 *
 * Null device driver for debugging purposes
 */

#include <errno.h>
#include <malloc.h>
#include <stdio.h>

#include <dmxcon/device.h>
#include <dmxcon/drivers/nulldev.h>

struct device_t *nulldev_create(const char *filename) {
  struct device_t *device = device_create();

  if (!device)
    return NULL;

  /* Setup device operations */
  device->ops.destroy = nulldev_destroy;
  device->ops.refresh = nulldev_refresh;
  device->ops.set_range = nulldev_set_range;
  device->ops.set_channel = nulldev_set_channel;

  return device;
}

int nulldev_destroy(struct device_t *device) {
  if (device) {
    free(device);
  }

  return 0;
}

int nulldev_write_command(struct device_t *device, const char *command) {
  return 0;
}

int nulldev_set_range(struct device_t *device, unsigned short end_addr) {
  if (device) {
    printf("nulldev: setting range to %u\n", end_addr);
    return 0;
  }

  errno = EINVAL;
  return -1;
}

int nulldev_set_channel(struct device_t *device, unsigned short channel, unsigned char value) {
  if (device) {
    printf("nulldev: setting channel %u to value %u\n", channel, value);
    return 0;
  }

  errno = EINVAL;
  return -1;
}

int nulldev_refresh(struct device_t *device) {
  if (device) {
    printf("nulldev: refreshing device\n");
    return 0;
  }

  errno = EINVAL;
  return -1;

}

